using System;
using System.Collections.Generic;
using System.Linq;
using System.Data;
using System.Runtime.Serialization;
using DIS_DAO.DAO;
using DIS_DAO.Helpers;

namespace DIS_DAO.DTO
{
	/// <summary>
	/// Data transfer object which is associated with Item table in database
	/// </summary>
	public class ItemDTO
	{
		public int ID { get; set; }
		public int IDCategory { get; set; }
		public string Name { get; set; }
		public double Price { get; set; }
		public string Image { get; set; }
		public string ContentType { get; set; }
        public CategoryDTO Category { get; set; }

		public static ItemDTO Translate(DataRow row)
		{
			var dto = new ItemDTO
			{
				ID = int.Parse(row["ID"].ToString()),
				IDCategory = int.Parse(row["IDCategory"].ToString()),
				Name = row["Name"].ToString(),
				Price = double.Parse(row["Price"].ToString()),
				Image = row["Image"].ToString(),
				ContentType = row["ContentType"].ToString(),
			};

            var rpt2 = new CategoryDAO(GlobalVariables.DbConnectionString);
            var objDS2 = rpt2.SelectByID(dto.IDCategory);
            if (objDS2 != null)
            {
                if (objDS2.Tables[0].Rows.Count > 0)
                {
                    dto.Category = CategoryDTO.Translate(objDS2.Tables[0].Rows[0]);
                }
            }

			return dto;
		}
	}
}